package cn.tellfish.studydemo.demo;

import java.util.Random;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

public class FixedThreadPool {


    public static void main(String[] args) {


        ExecutorService exec = Executors.newFixedThreadPool(12);


        Runnable task = new Runnable() {

            @Override
            public void run() {
                int rdm = new Random().nextInt(20) + 1000;
                try {
                    Thread.sleep(rdm);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println(rdm);
            }

        };

        for (int i = 0; i < 20; i++) {

            exec.execute(task);

        }

        exec.shutdown();
        try {
            exec.awaitTermination(30, TimeUnit.SECONDS);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

    }

}
